home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJTST200.ZIP / tests / libc / posix / sys / stat / svsf.c < prev   
Encoding:
C/C++ Source or Header  |  1995-12-23  |  740 b   |  44 lines

  1. /* stat() vs fstat() */
  2.  
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8.  
  9. #define SFMT    "%-10s %-10s %-10s\n"
  10. #define DFMT    "%-10s %10d %10d\n"
  11. #define XFMT    "%-10s 0x%08x 0x%08x\n"
  12. #define OFMT    "%-10s 0%09o 0%09o\n"
  13.  
  14. void
  15. try(const char *f)
  16. {
  17.   struct stat ss;
  18.   struct stat fs;
  19.   int o;
  20.  
  21.   o = open(f, O_RDONLY);
  22.   if (o < 0) return;
  23.  
  24.   stat(f, &ss);
  25.   fstat(o, &fs);
  26.  
  27. /*  close(o); */
  28.  
  29.   printf("\nFile: %s\n", f);
  30.   printf(SFMT, "field", "stat", "fstat");
  31.   printf(DFMT, "st_ino", ss.st_ino, fs.st_ino);
  32.   printf(OFMT, "st_mode", ss.st_mode, fs.st_mode);
  33.   printf(DFMT, "st_mtime", ss.st_mtime, fs.st_mtime);
  34. }
  35.  
  36. int
  37. main(void)
  38. {
  39.   try("svsf.c");
  40.   try(".");
  41.   try("/");
  42.   return 0;
  43. }
  44.